using System;
using System.Linq;
using System.Web.Mvc;
using Ezio.Models;

namespace Ezio.Controllers
{
    public class SalidasBodegasController : Controller
    {
        DataProvider Provider = new DataProvider();
        
        
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Agregar(SalidasBodegas SalidasBodega)
        {
            Provider.AddToSalidasBodegas(SalidasBodega);
            SalidasBodega.Fecha = DateTime.Now;
            return RedirectToAction("Index", new { Success = Provider.TrySaveChanges() });
        }
        public ActionResult Index(bool? Success)
        {
            string Message = Success.HasValue ? Success.Value ? "" : "Ha ocurrido un error al procesar su peticion" : "";
            
            ViewData["SalidasBodegas"] = Provider.SalidasBodegas.ToList();
            ViewData["Insumos"] = Provider.Insumos.ToList();
            ViewData["Bodegas"] = Provider.Bodegas.ToList();
            ViewData["Colegios"] = Provider.Colegios.ToList();
            ViewData["Message"] = Message;
            return View("Index");
        }
        public ActionResult Editar(int Id)
        {
            ViewData["SalidasBodega"] = Provider.SalidasBodegas.Single(t => t.IdSalidaBodega == Id);
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public bool Update(SalidasBodegas SalidasBodega)
        {
            SalidasBodegas mySalidasBodega= Provider.SalidasBodegas.Single(t => t.IdSalidaBodega == SalidasBodega.IdSalidaBodega);
            mySalidasBodega.Copy(SalidasBodega);
            return Provider.TrySaveChanges();
        }

    }
}
